
// 基础路径
const publicPath = process.env.VUE_APP_PUBLIC_PATH || '/'

// 拼接路径
const resolve = dir => require('path').join(__dirname, dir)

module.exports = {
  // 根据实际情况修改
  publicPath,
  lintOnSave: true,
  devServer: {
    port: 9999,
    publicPath, // 和 publicPath 保持一致
    disableHostCheck: process.env.NODE_ENV === 'development',
    proxy: {
      '/api': {
        target: 'http://localhost:9996/api',
        changeOrigin: true,
        pathRewrite: {
          ['^' + '/api']: ''
        }
      }
    }
  },
  // css
  css: {
    loaderOptions: {
      less: {
        modifyVars: {
          hack: `true; @import "${resolve('src/assets/themes/theme.less')}";`
        }
      }
    }
  },
  chainWebpack: config => {
    /**
     * 删除懒加载模块的 prefetch preload，降低带宽压力
     */
    config.plugins
      .delete('prefetch')
      .delete('preload')
    // 解决 cli3 热更新失效
    config.resolve
      .symlinks(true)
    // svg
    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
    svgRule
      .include
      .add(resolve('src/assets/svg-icons/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
    // image exclude
    const imagesRule = config.module.rule('images')
    imagesRule
      .test(/\.(png|jpe?g|gif|webp|svg)(\?.*)?$/)
      .exclude
      .add(resolve('src/assets/svg-icons/icons'))
      .end()
  }
}
